package com.xxxcompany.blog.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xxxcompany.blog.entity.User;
import com.xxxcompany.blog.service.IUserService;
import com.xxxcompany.blog.service.impl.UserServiceImpl;

@WebServlet("/registerchk")
public class RegisterServlet extends HttpServlet {
	
	IUserService userService = new UserServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();
		
		// 1. 获取用户提交的参数
		String username=req.getParameter("username");
		String password=req.getParameter("password");
		String nickname=req.getParameter("nickname");
		String email=req.getParameter("email");
		String phone=req.getParameter("phone");
		String headsculpture=req.getParameter("headsculpture");
		String sex=req.getParameter("sex");
		User user= new User(0,username,password,nickname,email,phone,headsculpture,sex,null,null);
		// 2. 调用service处理
		boolean result = userService.register(user);
		
		// 3. 显示结果/跳转页面
		if(result)
		{
			pw.print("注册成功");
		}
		else
		{
			pw.print("注册失败");
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}